﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace e3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                textBox2.Text = openFileDialog.FileName;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog();
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = openFileDialog.FileName;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            // 获取选择的文件路径
            string file1Path = textBox1.Text;
            string file2Path = textBox2.Text;

            if (string.IsNullOrEmpty(file1Path) || string.IsNullOrEmpty(file2Path))
            {
                MessageBox.Show("请选择两个文件");
                return;
            }

            try
            {
                // 读取文件内容
                string file1Content = File.ReadAllText(file1Path);
                string file2Content = File.ReadAllText(file2Path);

                // 合并内容
                string mergedContent = file1Content + Environment.NewLine + file2Content;

                // 创建新文件路径
                string exePath = Path.GetDirectoryName(Application.ExecutablePath);
                string dataFolderPath = Path.Combine(exePath, "Data");
                Directory.CreateDirectory(dataFolderPath); // 确保Data目录存在
                string mergedFilePath = Path.Combine(dataFolderPath, "merged_file.txt");

                // 写入合并后的内容到新文件
                File.WriteAllText(mergedFilePath, mergedContent);

                MessageBox.Show("文件合并成功，新文件保存在 " + mergedFilePath);
            }
            catch (Exception ex)
            {
                MessageBox.Show("发生错误：" + ex.Message);
            }
        }
    }
}
